﻿#region 命名空间

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Sharp.Domain.PlatformBoundedContext.UserModule.Aggregates;
using Sharp.Domain.Model;

#endregion

namespace Sharp.Domain.PlatformBoundedContext.PermissionModule.Aggregates
{
    /// <summary>
    /// 权限
    /// </summary>
    public partial class Permission : AggregateRoot
    {
        /// <summary>
        /// 权限
        /// </summary>
        public Permission()
        {
            UserGroups = new List<UserGroup>();
            Users = new List<User>();
        }
        public Permission(string id, string code, string title, string category, string parentId, int order, string route, string ico = "")
        {
            this.Id = Guid.Parse(id);
            this.Code = code;
            this.Title = title;
            this.Category = category;

            Guid _parentId;
            if (Guid.TryParse(parentId, out _parentId))
            {
                this.ParentId = _parentId;
            }
            else
            {
                this.ParentId = null;
            }
            this.OrderIndex = order;
            this.Route = route;
            this.Ico = ico;
        }

        /// <summary>
        /// 代码
        /// </summary>
        [Display(Name = "代码")]
        public string Code { get; set; }

        /// <summary>
        ///     标题
        /// </summary>
        [Display(Name = "标题")]
        public string Title { get; set; }

        /// <summary>
        /// 分类
        /// </summary>
        [Display(Name = "权限类型")]
        public string Category { get; set; }

        /// <summary>
        ///     父id
        /// </summary>
        /// <value>父Id</value>
        public System.Guid? ParentId { get; set; }

        /// <summary>
        ///     排序索引
        /// </summary>
        /// <value>排序的值</value>
        public int OrderIndex { get; set; }

        /// <summary>
        ///     程序路由
        /// </summary>
        public string Route { get; set; }
        /// <summary>
        /// 图标或者是css class的名称
        /// </summary>
        public string Ico { get; set; }
        /// <summary>
        /// 系统代号
        /// </summary>
        public string SystemCode { get; set; }
        /// <summary>
        ///     用户组
        /// </summary>
        public virtual ICollection<UserGroup> UserGroups { get; set; }

        /// <summary>
        ///     用户
        /// </summary>
        public virtual ICollection<User> Users { get; set; }
    }
}